﻿using System;
using System.Collections.Generic;
using AdAggregator.Advertisement;
using AdAggregator.Attribute;
using RealEstateAggregator.Utils;

namespace RealEstateAggregator.Models
{
    public class MyAdvertisement : BaseAdvertisement
    {
        public String Title { get; set; }
        public String Photo { get; set; }
        [Comparable(1)]
        public String Voivodship { get; set; }
        [Comparable(2)]
        public String City { get; set; }
        [Comparable(3)]
        public String District { get; set; }
        [Comparable(4)]
        public String Street { get; set; }
        public String Location { get { return BuildLocationString(); } }
        public AdvertisementType AdvertisementType { get; set; }
        public EstateType EstateType { get; set; }
        public MarketType MarketType { get; set; }
        [Sortable("Cena")]
        [Comparable(4)]
        public decimal? Price { get; set; }
        [Sortable("Cena za metr")]
        [Comparable(4, 1)]
        public decimal? PricePerMeter { get; set; }
        [Sortable("Powierzchnia")]
        [Comparable(4)]
        public decimal? Area { get; set; }
        [Comparable(3)]
        public int? Floor { get; set; }
        [Comparable(3)]
        public int? YearBuilt { get; set; }
        [Comparable(3)]
        public int? RoomCount { get; set; }
        public String AdSource { get; set; }
        [Sortable("Data modyfikacji")]
        public DateTime? Modified { get; set; }

        public MyAdvertisement(MyAdvertisement other)
        {
            Title = other.Title;
            Photo = other.Photo;
            Link = other.Link;
            Voivodship = other.Voivodship;
            City = other.City;
            District = other.District;
            Street = other.Street;
            AdvertisementType = other.AdvertisementType;
            EstateType = other.EstateType;
            MarketType = other.MarketType;
            Price = other.Price;
            PricePerMeter = other.PricePerMeter;
            Area = other.Area;
            Floor = other.Floor;
            YearBuilt = other.YearBuilt;
            RoomCount = other.RoomCount;
            AdSource = other.AdSource;
            Modified = other.Modified;
        }

        public MyAdvertisement()
        {
        }

        private string BuildLocationString()
        {
            var strings = new List<string>();
            if (!String.IsNullOrEmpty(Voivodship)) strings.Add(Voivodship);
            if (!String.IsNullOrEmpty(City)) strings.Add(City);
            if (!String.IsNullOrEmpty(District)) strings.Add(District);
            if (!String.IsNullOrEmpty(Street)) strings.Add(Street);
            var location = String.Join(", ", strings);
            return location;
        }
    }
}